﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>蓝天之约 - 后台管理系统</title>
	<!-- bootstrap 3.0.2 -->
	<link href="/resource/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<!-- font Awesome -->
	<link href="/resource/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<!-- iCheck for checkboxes and radio inputs -->
	<link href="/resource/css/iCheck/all.css" rel="stylesheet" type="text/css" />
	<!-- Theme style -->
	<link href="/resource/css/style.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" type="text/css" href="/resource/js/webuploader-0.1.5/webuploader.css">
	<link rel="stylesheet" type="text/css" href="/resource/js/jQueryMessage/css/message.skin.css" />
</head>
<body>
<div class="row">
	<div class="col-md-12">
		<h1 class="panel-heading">修改附件</h1>
		<!--breadcrumbs start -->
		<ul class="breadcrumb">
			<li><a href="/admin/dashboard/toIndex"><i class="fa fa-home"></i> 首页</a></li>
			<li class="active">修改附件</li>
		</ul>
		<!--breadcrumbs end -->
	</div>
</div>
<div class="row">
	<div class="col-lg-12">
		<section class="panel">
			<div class="panel-body">
				<form class="col s12" id="form1" enctype="multipart/form-data" th:action="@{/admin/attachment/update}" onsubmit="return validateForm();" method="post">
					<input type="hidden" th:value="${attachment.id}" id="id" name="id"/>
					<input name="filename" id="filename" type="hidden" th:value="${attachment.filename}" />
					<input name="filepath" id="filepath" type="hidden" th:value="${attachment.filepath}" />
					<input name="filetype" id="filetype" type="hidden" th:value="${attachment.filetype}" />
					<input name="filesize" id="filesize" type="hidden" th:value="${attachment.filesize}"/>

					<div class="form-group form-control-medium">
						<label for="info">描述：</label>
						<input id="info" name="info" type="text" th:value="${attachment.info}" class="form-control"/>
					</div>
					<div id="uploader" class="wu-example">
						<div id="file-priview" class="file-priview"></div>
						<div class="btns">
							<div id="picker">选择文件...</div>
						</div>
					</div>
					<div class="form-btn-group-left">
						<button type="submit" class="btn btn-info">保存</button>
					</div>
				</form>
			</div>
		</section>
	</div>
</div>
<!-- jQuery 2.0.2 -->
<script src="/resource/js/jquery.min.js" type="text/javascript"></script>
<!-- Bootstrap -->
<script src="/resource/js/bootstrap.min.js" type="text/javascript"></script>
<!-- iCheck -->
<script src="/resource/js/plugins/iCheck/icheck.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/resource/js/webuploader-0.1.5/webuploader.js"></script>
<script type="text/javascript" src="/resource/js/jQueryMessage/js/jquery.plugin.message.js"></script>
<script type="text/javascript" th:inline="javascript">

	var thumbnailWidth = 178,thumbnailHeight = 178;


	/* 保存方法 */
	function validateForm(){
		var itemName = $("#itemName").val();
		if(itemName == null || itemName==''){
			$("body").MessageBox({
				type: 'error',
				message:'变量名称不能为空！',
				timeout:3000,
				callbak:null
			});
			return false;
		}
		return true;
	}

	function initUploader(picker,el){
		var uploader = WebUploader.create({
			auto: true,
			// swf文件路径
			swf: '/resource/js/webuploader-0.1.5/Uploader.swf',
			// 文件接收服务端。
			server: '/upload/uploadFile',
			// 选择文件的按钮。可选。
			// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: '#' + picker,
			fileNumLimit: 1,
			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false
		});
		uploader.on('fileQueued', function(file) {
			$("#"+el).text(file.name);
		});
		uploader.on('uploadSuccess', function(file, response) {
			console.log(response);
			$("body").MessageBox({
				type: 'success',
				message: '上传成功！',
				timeout:3000,
				callbak:null
			});
			$("#filename").val(response.data.originalFilename);
			$("#filepath").val(response.data.filepath);
			$("#filesize").val(response.data.filesize);
			$("#filetype").val(response.data.filetype);
		});
		uploader.on('uploadError', function( file ) {
			$("body").MessageBox({
				type: 'error',
				message: '上传失败！',
				timeout:3000,
				callbak:null
			});
		});
	}


	function renderCheckBox(){
		$('input').on('ifChecked', function(event) {
			$(this).parents('li').addClass("task-done");
			console.log('ok');
		});
		$('input').on('ifUnchecked', function(event) {
			$(this).parents('li').removeClass("task-done");
			console.log('not');
		});

		$('input[type="checkbox"].flat-grey, input[type="radio"].flat-grey').iCheck({
			checkboxClass: 'icheckbox_flat-grey',
			radioClass: 'iradio_flat-grey'
		});
	}
	$(document).ready(function () {
		initUploader("picker", "file-priview", "filepath");
		renderCheckBox();
	});
</script>
</body>
</html>
